package com.qf.zuoye0620.config;

import com.qf.zuoye0620.filter.RequiredParamFilter;
import com.qf.zuoye0620.interceptor.AuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author UNIQ7xi
 * @Date 2023/6/20 19:14
 * @Version v1.8
 **/
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private AuthInterceptor authInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authInterceptor).addPathPatterns("/**");
    }

    @Bean
    public FilterRegistrationBean<RequiredParamFilter> requiredParamFilter() {
        FilterRegistrationBean<RequiredParamFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(new RequiredParamFilter());
        registration.addUrlPatterns("/*");
        registration.setName("requiredParamFilter");
        registration.setOrder(1);
        return registration;
    }
}
